#include<bits/stdc++.h>
#define db double
using namespace std;
using ll=long long;
const int N=5e5+5,M=2e6+5;
bool Mst;
int n,k[N];
vector<int>a[N];
int c;
ll b[N];
struct node{
	int l,v;
	bool operator <(const node P){return l<P.l;}
}pr[M];
int cnt=0;
inline void add(int l,int r){pr[++cnt]={l,1},pr[++cnt]={r+1,-1};}
ll vis[M];
int ton[M],cc;
inline int gid(int x){return lower_bound(ton+1,ton+1+cc,x)-ton;}
inline ll solve(int x){
	int bel=gid(x);
	if(~vis[bel])return vis[bel];
	ll res=0;
	cnt=0;
	for(int i=1;i<=n;i++){
		int las=0;
		for(int j=1;j<=k[i];j++){
			if(!las){
				las=a[i][j];
			}
			else if(a[i][j]-a[i][j-1]>=x){
				add(las,a[i][j-1]+x-1);
				las=a[i][j];
			}
		}
		add(las,a[i][k[i]]+x-1);
	}
	sort(pr+1,pr+1+cnt);
	int sum=0;
	int las=pr[1].l;
	for(int i=1;i<=cnt;i++){
		int cur=0,now=pr[i].l,pos=i;
		res+=1ll*(now-las)*sum*c;las=pr[i].l;
		while(pos<cnt&&pr[pos+1].l==now)pos++;
		for(int j=i;j<=pos;j++){
			if(pr[j].v==1)cur++,sum++;
			else sum--;
		}
		res+=b[cur];
		i=pos;
	}
	return vis[bel]=res;
}
ll mi;
vector<int>ans;
mt19937 rnd(time(0));
const unsigned int PP=(1ll<<32)-1;
inline db pro(){return 1.0*rnd()/PP;}
inline int mr(int l,int r){return rnd()%(r-l+1)+l;}
int sk;
ll tmp[M];
inline void ad(int x){
	if(!ans.empty()&&ans.back()==x)return ;
	ans.push_back(x);
}
bool tmout(){return clock()>900;}
bool Med;
int main(){
	cerr<<(&Mst-&Med)/1024.0/1024.0<<"\n";
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	memset(vis,-1,sizeof vis);
	mi=4e18;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>k[i];
		a[i].resize(k[i]+2);
		for(int j=1;j<=k[i];j++)cin>>a[i][j],ton[++cc]=a[i][j]-a[i][j-1];
		sk+=k[i];
	}
	ton[++cc]=0;
	sort(ton+1,ton+1+cc);cc=unique(ton+1,ton+1+cc)-ton-1;
	cin>>c;
	for(int i=1;i<=n;i++)cin>>b[i],b[i]*=i;
	for(int i=1;i<=cc;i++)ton[i]++;
	if(1ll*cc*sk<=2e7){
		for(int i=1;i<=cc;i++){
			ll res=solve(ton[i]);
			if(res<mi)mi=res,ans.clear(),ans.push_back(ton[i]);
			else if(res==mi)ans.push_back(ton[i]);
		}
	}
	else{
		int curx=mr(100,500)/1e4*cc;
		curx++;
		ans.push_back(curx);
		mi=solve(ton[curx]);
		for(db T=1e5,lim=1e-1,delta=0.99;T>=lim;T*=delta){
			int px=curx;
			curx+=mr(1-curx,cc-curx)*T/1e5;
			ll res=solve(ton[curx]);
			if(res<mi)mi=res,ans.clear(),ad(ton[curx]);
			else if(res==mi)ad(ton[curx]);
			else if(exp(1.0*(mi-res)/T)<=pro())curx=px;
//			if(tmout())break;
		}
		int s=gid(ans[0]);
		for(int i=max(1,s-1);i<=min(cc,s+1);i++){
			ll res=solve(ton[i]);
			if(res<mi)mi=res,ans.clear(),ans.push_back(ton[i]);
			else if(res==mi)ans.push_back(ton[i]);
		}
	}
	int ansc=0;
	sort(ans.begin(),ans.end());
	int len=ans.size();
	ans.push_back(-1);
	for(int i=0;i<len;i++){
		if(ans[i]^ans[i+1])tmp[++ansc]=ans[i];
	}
	cout<<mi<<" "<<ansc<<"\n";
	for(int i=1;i<=ansc;i++)cout<<tmp[i]<<" ";
	return 0;
}

